//
//  SupermarketUtil.m
//  Supermarket
//
//  Created by qskj-ios on 2018/12/10.
//  Copyright © 2018年 com.qiansheng. All rights reserved.
//

#import "SupermarketUtil.h"

#define nullDataTag 20000002
static NSString * const kDoctorDataCache = @"SUPERMARKET_DATA_CACHE_%@_%@";

@implementation SupermarketUtil

+ (void)saveDataWithKey:(NSString *)key ofValue:(id)value {
    NSString *k = [NSString stringWithFormat:kDoctorDataCache, @"", key];
    [[NSUserDefaults standardUserDefaults] setObject:value forKey:k];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)clearDataWithKey:(NSString *)key {
    NSString *k = [NSString stringWithFormat:kDoctorDataCache, @"", key];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:k];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (id)getDataWithKey:(NSString *)key {
    NSString *k = [NSString stringWithFormat:kDoctorDataCache, @"", key];
    return [[NSUserDefaults standardUserDefaults] objectForKey:k];
}

/** 无数据时页面展示 */
+ (void)setNullDataView:(UIView *)view withData:(NSArray *)array {
    for (UIView *subv in view.subviews) {
        if (subv.tag == nullDataTag) {
            [subv removeFromSuperview];
        }
    }
    if (array.count > 0) {
        return;
    }
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"content"]];
    img.tag = nullDataTag;
    img.contentMode = UIViewContentModeScaleAspectFit;
    [view addSubview:img];
    img.frame = CGRectMake(0, 0, 50, 50);
    img.center = CGPointMake(view.center.x, view.center.y-60);
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, view.center.y-10, kScreenWidth, 20)];
    title.tag = nullDataTag;
    if (UserInfo.id > 0) {
        title.text = @"空空如也";
    } else {
        title.text = @"请先扫描客户信息";
    }
    title.font = [UIFont systemFontOfSize:20];
    title.textColor = kTextColorThree;
    title.textAlignment = NSTextAlignmentCenter;
    [view addSubview:title];
}

@end
